package net.minecraft.src;
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.

// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode 

import net.lax1dude.eaglercraft.EaglerAdapter;
import net.lax1dude.eaglercraft.EaglercraftRandom;
import net.lax1dude.eaglercraft.TextureLocation;
import net.lax1dude.eaglercraft.adapter.Tessellator;

public class RenderPainting extends Render {
	
	private static final TextureLocation paintingTexture = new TextureLocation("/art/kz.png");

	public RenderPainting() {
		rand = new EaglercraftRandom();
	}

	public void func_158_a(EntityPainting entitypainting, double d, double d1, double d2, float f, float f1) {
		rand.setSeed(187L);
		EaglerAdapter.glPushMatrix();
		EaglerAdapter.glTranslatef((float) d, (float) d1, (float) d2);
		EaglerAdapter.glRotatef(f, 0.0F, 1.0F, 0.0F);
		EaglerAdapter.glEnable(32826 /* GL_RESCALE_NORMAL_EXT */);
		paintingTexture.bindTexture();
		EnumArt enumart = entitypainting.art;
		float f2 = 0.0625F;
		EaglerAdapter.glScalef(f2, f2, f2);
		func_159_a(entitypainting, enumart.sizeX, enumart.sizeY, enumart.offsetX, enumart.offsetY);
		EaglerAdapter.glDisable(32826 /* GL_RESCALE_NORMAL_EXT */);
		EaglerAdapter.glPopMatrix();
	}

	private void func_159_a(EntityPainting entitypainting, int i, int j, int k, int l) {
		float f = (float) (-i) / 2.0F;
		float f1 = (float) (-j) / 2.0F;
		float f2 = -0.5F;
		float f3 = 0.5F;
		for (int i1 = 0; i1 < i / 16; i1++) {
			for (int j1 = 0; j1 < j / 16; j1++) {
				float f4 = f + (float) ((i1 + 1) * 16);
				float f5 = f + (float) (i1 * 16);
				float f6 = f1 + (float) ((j1 + 1) * 16);
				float f7 = f1 + (float) (j1 * 16);
				func_160_a(entitypainting, (f4 + f5) / 2.0F, (f6 + f7) / 2.0F);
				float f8 = (float) ((k + i) - i1 * 16) / 256F;
				float f9 = (float) ((k + i) - (i1 + 1) * 16) / 256F;
				float f10 = (float) ((l + j) - j1 * 16) / 256F;
				float f11 = (float) ((l + j) - (j1 + 1) * 16) / 256F;
				float f12 = 0.75F;
				float f13 = 0.8125F;
				float f14 = 0.0F;
				float f15 = 0.0625F;
				float f16 = 0.75F;
				float f17 = 0.8125F;
				float f18 = 0.001953125F;
				float f19 = 0.001953125F;
				float f20 = 0.7519531F;
				float f21 = 0.7519531F;
				float f22 = 0.0F;
				float f23 = 0.0625F;
				Tessellator tessellator = Tessellator.instance;
				tessellator.startDrawingQuads();
				tessellator.setNormal(0.0F, 0.0F, -1F);
				tessellator.addVertexWithUV(f4, f7, f2, f9, f10);
				tessellator.addVertexWithUV(f5, f7, f2, f8, f10);
				tessellator.addVertexWithUV(f5, f6, f2, f8, f11);
				tessellator.addVertexWithUV(f4, f6, f2, f9, f11);
				tessellator.setNormal(0.0F, 0.0F, 1.0F);
				tessellator.addVertexWithUV(f4, f6, f3, f12, f14);
				tessellator.addVertexWithUV(f5, f6, f3, f13, f14);
				tessellator.addVertexWithUV(f5, f7, f3, f13, f15);
				tessellator.addVertexWithUV(f4, f7, f3, f12, f15);
				tessellator.setNormal(0.0F, -1F, 0.0F);
				tessellator.addVertexWithUV(f4, f6, f2, f16, f18);
				tessellator.addVertexWithUV(f5, f6, f2, f17, f18);
				tessellator.addVertexWithUV(f5, f6, f3, f17, f19);
				tessellator.addVertexWithUV(f4, f6, f3, f16, f19);
				tessellator.setNormal(0.0F, 1.0F, 0.0F);
				tessellator.addVertexWithUV(f4, f7, f3, f16, f18);
				tessellator.addVertexWithUV(f5, f7, f3, f17, f18);
				tessellator.addVertexWithUV(f5, f7, f2, f17, f19);
				tessellator.addVertexWithUV(f4, f7, f2, f16, f19);
				tessellator.setNormal(-1F, 0.0F, 0.0F);
				tessellator.addVertexWithUV(f4, f6, f3, f21, f22);
				tessellator.addVertexWithUV(f4, f7, f3, f21, f23);
				tessellator.addVertexWithUV(f4, f7, f2, f20, f23);
				tessellator.addVertexWithUV(f4, f6, f2, f20, f22);
				tessellator.setNormal(1.0F, 0.0F, 0.0F);
				tessellator.addVertexWithUV(f5, f6, f2, f21, f22);
				tessellator.addVertexWithUV(f5, f7, f2, f21, f23);
				tessellator.addVertexWithUV(f5, f7, f3, f20, f23);
				tessellator.addVertexWithUV(f5, f6, f3, f20, f22);
				tessellator.draw();
			}

		}

	}

	private void func_160_a(EntityPainting entitypainting, float f, float f1) {
		int i = MathHelper.floor_double(entitypainting.posX);
		int j = MathHelper.floor_double(entitypainting.posY + (double) (f1 / 16F));
		int k = MathHelper.floor_double(entitypainting.posZ);
		if (entitypainting.direction == 0) {
			i = MathHelper.floor_double(entitypainting.posX + (double) (f / 16F));
		}
		if (entitypainting.direction == 1) {
			k = MathHelper.floor_double(entitypainting.posZ - (double) (f / 16F));
		}
		if (entitypainting.direction == 2) {
			i = MathHelper.floor_double(entitypainting.posX - (double) (f / 16F));
		}
		if (entitypainting.direction == 3) {
			k = MathHelper.floor_double(entitypainting.posZ + (double) (f / 16F));
		}
		float f2 = renderManager.worldObj.getLightBrightness(i, j, k);
		EaglerAdapter.glColor3f(f2, f2, f2);
	}

	public void doRender(Entity entity, double d, double d1, double d2, float f, float f1) {
		func_158_a((EntityPainting) entity, d, d1, d2, f, f1);
	}

	private EaglercraftRandom rand;

	@Override
	protected boolean loadDownloadableImageTexture(String s, String s1) {
		return true;
	}
}
